<%@ Page Language="C#" Inherits="IBuyAdventure.PageBase" src="../components/stdpage.cs" clienttarget=downlevel %>
<%@ Register TagPrefix="IBA" TagName="Header" Src="..\UserControl\Header.ascx" %>
<%@ Register TagPrefix="IBA" TagName="Categories" Src="..\UserControl\Categories.ascx" %>
<%@ Register TagPrefix="IBA" TagName="Footer" Src="..\UserControl\Footer.ascx" %>

<%@ Import Namespace="System.Data" %>

<HTML>
  <HEAD>
    <TITLE>IBuyAdventure Catalog</TITLE>
  </HEAD>
 
  <script language="C#" runat="server" >


      void Page_Load(Object sender, EventArgs e) {
         PopulateOrderList();
      }              

      String GetCustomerID() {
       
        if (User.Identity.Name != "") {
          return Context.User.Identity.Name;
        }
        else {
	   if (Session["AnonUID"] == null)
		Session["AnonUID"] = Guid.NewGuid();
	   return Session["AnonUID"].ToString();
        }
      }
              
      void PopulateOrderList() {
      
        // Popoulate list with updated shopping cart data
        
        IBuyAdventure.OrdersDB orders = new IBuyAdventure.OrdersDB(getConnStr());  
        
        DataSet ds = orders.GetOrdersForCustomer(GetCustomerID());

        MyList.DataSource = ds;
        MyList.DataBind();   

        // Hide the clear button if there are no items to delete.
        if  ( MyList.Items.Count == 0 ) {
           ClearButton.Visible = false;
           MyList.Visible = false;
           Status.Text = "No orders have been placed to date.";
           }

      }
      
      void ClearOrderHistory(Object sender, EventArgs e) {
       
        IBuyAdventure.OrdersDB orders = new IBuyAdventure.OrdersDB(getConnStr());    
        orders.DeleteOrdersForCustomer( GetCustomerID() );
        PopulateOrderList();
      }
      
  </script>

  <BODY BACKGROUND="/IBuyAdventure/images/back_sub.gif"> 

    <form runat="server">

      <FONT FACE="Verdana, Arial, Helvetica" SIZE=2>

        <TABLE BORDER=0VALIGN=TOP width=100%>
          
          <tr>
            <td colspan=5>        
              <IBA:Header id="Header" runat="server"/>
            </td>
          </tr>
          
          <!--Begin Navigational Buttons-->

          <TR VALIGN=TOP>
            <TD width=20% ALIGN=LEFT VALIGN=TOP>

              <IBA:Categories id="Categories" runat="server"/>
              
              
            </TD>
            <td>
              &nbsp;&nbsp;
            </td>
            <TD valign=top align=left width=80%>
            
              <h2>Your Account</h2>
              
                <FONT FACE="Verdana, Arial, Helvetica" SIZE=2>
                <asp:label id="Status" runat="server">You have placed the following orders to date:</asp:label><BR><BR>
                <asp:repeater id="MyList" runat="server" >
                


      <headertemplate>
        <table width="100%" style="font: 10pt verdana" CellPadding=3  CellSpacing="0" border=0>
          <tr style="background-color:800000;color:#ffffff">
            <th>
              Order Date
            </th>
            <th>
              Order Value
            </th>
          </tr>
      </headertemplate>

      <itemtemplate>
        <tr style="background-color:FFECD8">
          <td>
            <%# DataBinder.Eval(Container.DataItem, "Ordered") %>
          </td>
          <td>
            <%# DataBinder.Eval(Container.DataItem, "TotalValue","{0:C}") %>
          </td>
        </tr>
      </itemtemplate>

      <footertemplate>
        </table>
      </footertemplate>
                </asp:repeater>
                <BR>
                <asp:button id=ClearButton text="Clear Order History" OnClick="ClearOrderHistory" runat="server"/>

                </FONT>            
              </table>
            </TD>
          </TR>
          <TR><TD><TD>
        <IBA:footer runat="server"/>
        </TABLE>

      </FONT>
    </form>

  </BODY>
</HTML>
